package org.bear.tree;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Tree {
    public TreeNode root;

    public Tree(List<Integer> nodeValueList) {
        LinkedList<TreeNode> queue = new LinkedList<>();
        TreeNode r = new TreeNode(nodeValueList.get(0));
        queue.add(r);
        root = r;
        int i = 1;
        while (i < nodeValueList.size()) {
            TreeNode t = queue.removeFirst();
            if (nodeValueList.get(i)!=null){
                TreeNode left = new TreeNode(nodeValueList.get(i));
                t.left = left;
                queue.add(left);
            }
            i++;
            if (nodeValueList.get(i)!=null){
                TreeNode right = new TreeNode(nodeValueList.get(i));
                t.right = right;
                queue.add(right);
            }
            i++;
        }
        System.out.println("tree finished");
    }

    public static void main(String[] args) {
        new Tree(new ArrayList<>(Arrays.asList(1,0,1,0,1,0,1)));
    }

}
